package com.neusoft.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.neusoft.po.Business;

@Mapper
public interface BusinessMapper {
	
	@Select("select * from business where businessId=#{businessId} and businessPassword=#{businessPassword}")
	public Business getBusinessByIdByPass(Business business);

	@Select("select * from business where orderTypeId=#{orderTypeId} order by businessId")
	public List<Business> listBusinessByOrderTypeId(Integer orderTypeId);

	@Select("select * from business where businessId=#{businessId}")
	public Business getBusinessById(Integer businessId);

	// update
	@Update("update business set businessPassword=#{businessPassword},businessName=#{businessName},businessAddress=#{businessAddress},businessExplain=#{businessExplain},businessImg=#{businessImg},starPrice=#{starPrice},deliveryPrice=#{deliveryPrice} where businessId=#{businessId}")
	public int updateBusiness(Business business);

	// delete
	@Delete("delete from business where businessId=#{businessId}")
	public int removeBusiness(Integer businessId);

	// save
	@Insert("insert into business(businessPassword,businessName,businessAddress,businessExplain,businessImg,orderTypeId,starPrice,deliveryPrice,remarks) values(#{businessPassword},#{businessName},#{businessAddress},#{businessExplain},#{businessImg},#{orderTypeId},#{starPrice},#{deliveryPrice},null)")
	@Options(useGeneratedKeys = true, keyProperty = "businessId", keyColumn = "businessId")
	public int saveBusiness(Business business);
	
	//getnewId
	@Select("select * from business order by businessId DESC LIMIT 1;")
	public int getNewIds();
}
